<?php

/**
* Database
* @link ezSQL http://justinvincent.com/ezsql
*/

class Database { // extends Medoo 
	
	private $config;
	public $pdodb;
	
	public function __construct() {
		$this->init();
	}
	
	private function init() {
		$this->loadConfig();
		$this->connect_db();
		//$this->createTable();
	}
	
	public function connect_db($name = 'master') {
		$config = $this->config['Database'];
		loadClass('db', 'system');
		
	}
	
	/*private function connect_db() {
		$config = $this->config['Database'];
		loadClass('db', 'system');
		$this->pdodb = new medoo([
			// 必须配置项
			'database_type' => 'mysql',
			'database_name' => $config['dbName'],
			'server' => $config['host'],
			'username' => $config['user'],
			'password' => $config['pass'],
			'charset' => $config['charset'],
			// 可选参数
			'port' => $config['port'],
		
			// 可选，定义表的前缀
			'prefix' => $config['prefix'],
		
			// 连接参数扩展, 更多参考 http://www.php.net/manual/en/pdo.setattribute.php
			'option' => [
				PDO::ATTR_CASE => PDO::CASE_NATURAL
			]
		]);
		//parent::Medoo($config['user'], $config['pass'], $config['dbName'], $config['host'], $config['charset']);

		/*$conn = mysql_connect($config['host'], $config['user'], $config['pass']) or die("error: database connect fail !");
		mysql_select_db($config['dbName']);
		mysql_query('set names "' . $config['charset'] . '"');
		self::$conn = $conn;* /
	}*/
	
	/*public function createTable() {
		$tableFile = WEB_PATH . '/resource/' . $this->config['Controller']['defApp'] . '.sql';
		$sql_create = file_get_contents($tableFile);
		$q = mysql_query($sql_create);
		$q || die('error: cerate table failed');
	}*/
	
	private function loadConfig() {
		$this->config = System::$config;
	}
}